home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12699 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.itg.ti.com!usenet
  2. From: dwnw%mimi@magic.itg.ti.com (Doug Nintzel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Allocating memory in windows programs
  5. Date: 21 Mar 1996 07:30:40 GMT
  6. Organization: TI(itg/is&s)
  7. Distribution: world
  8. Message-ID: <4ir0j0$2ge@dsk92.itg.ti.com>
  9. NNTP-Posting-Host: ows-14.itg.ti.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. Hello, I am new at windows programming. I am using MS-SDK/c++. I am using the 
  15. below code to allocate memory....
  16. /****************************************************************************/
  17. memtst()
  18. {
  19. char FAR*str;
  20. i=0;
  21.  
  22. /* 
  23. if((str=(char*)malloc(sizev))==NULL){MessageBox(hWnd,"GlobLock()failed","globl
  24. ock",MB_OK);return(0);}
  25.    for(i=0;i<555;++i)str[i]='x';str[25]='\0';
  26.  */
  27. if((hmem=GlobalAlloc(GHND,100))==NULL){MessageBox(hWnd,"GlobAlloc(),
  28.     failed",MB_OK);return(0);}
  29. str=(char FAR*)GlobalLock(hmem);
  30. if(str==NULL){MessageBox(hWnd,"GlobLock()failed","globlock",MB_OK);return(0);}
  31. MessageBox(hWnd,str,"ALLOC/LOCK OK",MB_OK);
  32. strcpy(str,"mem test ok");
  33. MessageBox(hWnd,str,"str content",MB_OK);
  34. }
  35. /****************************************************************************/
  36. ...it crashes at strcpy(str,"mem test ok");...
  37.  
  38. I have also tried to used the commented out malloc() test instead of     
  39. GlobalAlloc().
  40. I have tried several other changes/combinations w/no luck. 
  41. I have also checked c++ FAQ's and checked several book stores.
  42. I am running out of ideas!!!...Please help.....
  43.  
  44. Thanks, Doug
  45.  
  46.